/* edited by wildw1ng */
disableSerialization;

waitUntil {!isNil "BIS_fnc_sortNum" && !isNil "LIB_mp_flags" && !LIB_mp_cutscene};

sleep 0.1;
_miny = 0.03;

while {!LIB_mp_cutscene} do 
{
	3 cutRsc ["hud", "PLAIN"];
	_ui = uiNamespace getVariable "hud";
	_y = _miny + 0.03 * count LIB_mp_activesides;
	_i = 0;
	
	/* ticketsBlue */
	_hud = _ui displayCtrl 2001;
	_text = format ["%1", LIB_mp_scores select 0];
	_hud ctrlSetText _text;
	_hud ctrlCommit 0;
	
	/* ticketsRed */
	_hud = _ui displayCtrl 2002;
	_text = format ["%1", LIB_mp_scores select 1];
	_hud ctrlSetText _text;
	_hud ctrlCommit 0;
	
	/* ticketsGreen */
	_hud = _ui displayCtrl 2003;
	_text = format ["%1", LIB_mp_scores select 2];
	_hud ctrlSetText _text;
	_hud ctrlCommit 0;
	
	/* flagStatus */
	{
		if (!isNull _x) then
		{
			_color = [0.9, 0.9, 0.9, 0.6];			
			switch (_x getVariable "side") do
			{
				case west:{_color = [0.0, 0.3, 0.6, 0.6]};
				case east:{_color = [0.5, 0.0, 0.0, 0.6]};
				case resistance:{_color = [0.0, 0.5, 0.0, 0.6]};
			};
			_hud = _ui displayCtrl (3000 + _i);
			_hud ctrlSetPosition [safezoneX + (safezoneW/2) - 0.287 + _y, safezoneY + 0.032 * safezoneH];
			_y = _y + 0.03;
			_hud ctrlSetTextColor _color;
			_hud ctrlCommit 0;
			_i = _i + 1;
		};
	} forEach LIB_mp_flags;

	/* time limit */
	if (LIB_mp_timelimit > 0) then
	{
		_hud = _ui displayCtrl 2004;
		_hud ctrlSetPosition [(0.875 - 0.006) * safezoneW + safezoneX, 0.008 * safezoneH + safezoneY];
		_timeleft = ceil (LIB_mp_timelimit - time);
		_zero = if (_timeleft mod 60 < 10) then {0;} else {"";};
		_text = if (_timeleft >= 0) then {format ["%1:%2%3", abs (floor (_timeleft * 0.01666666667)), _zero, _timeleft mod 60];} else {"";};
		_hud ctrlSetText _text;
		_hud ctrlCommit 0;
	};
	
	_flag = objNull;
	{
		if ([getPosATL vehicle player select 0, getPosATL vehicle player select 1] distance [getPosATL _x select 0, getPosATL _x select 1] <= LIB_mp_sectorsize) then
		{
			_flag = _x;
		};
	} forEach LIB_mp_flags;

	if (!isNull _flag) then
	{
		_color = [0.9, 0.9, 0.9, 0.6];
		switch (_flag getVariable "side") do
		{
			case west:{_color = [0.0, 0.3, 0.6, 0.6]};
			case east:{_color = [0.5, 0.0, 0.0, 0.6]};
			case resistance:{_color = [0.0, 0.5, 0.0, 0.6]};
		};
		/* progress bar */
		_hud = _ui displayCtrl 2005;
		_hud ctrlSetPosition [safezoneX + (safezoneW/2) - ((0.12375 * safezoneW)/2), safezoneY + 0.07 * safezoneH, 0.12375 * safezoneW * ((_flag getVariable ["seizetime", LIB_mp_seizetime]) / LIB_mp_seizetime), 0.012 * safezoneH];
		_hud ctrlSetBackgroundColor _color;
		_hud ctrlCommit 0;
		/* progress bar text */
		_hud = _ui displayCtrl 2006;
		_hud ctrlSetPosition [safezoneX + (safezoneW/2) - ((0.12375 * safezoneW)/2), safezoneY + 0.07 * safezoneH];
		_text = "";
		_text = (_flag getVariable "name");
		_hud ctrlSetText _text;
		_hud ctrlCommit 0;
	};
	sleep 0.1;
};